<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of cXMLController
 *
 * @author gt
 */
class cXMLController {

    public $root = "gbase_config";
    public $file = "";
    public $data = "";
    private $xmlObj = "";

    function writeArrayToXML() {
        $this->xmlObj = new SimpleXMLElement("<?xml version=\"1.0\"?><" . $this->root . "></" . $this->root . ">");
        $this->arrayToXml($this->data, $this->xmlObj);
        $this->xmlObj->asXML($this->file);
    }

// function defination to convert array to xml
    private function arrayToXml($data, &$xmlObj) {
        foreach ($data as $key => $value) {
            if (is_array($value)) {
                if (!is_numeric($key)) {
                    $subnode = $xmlObj->addChild("$key");
                    $this->arrayToXml($value, $subnode);
                } else {
                    $this->arrayToXml($value, $xmlObj);
                }
            } else {
                $xmlObj->addChild("$key", "$value");
            }
        }
    }

    function readXmlFile() {
//        echo file_exists($this->file).'asdad';exit;
        if (file_exists($this->file)) {
            return simplexml_load_file($this->file);
        } else {
            return false;
        }
    }

}

?>
